<?php
namespace Modules\Mall\Http\Controllers;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Modules\Mall\Entities\Cate;
use Modules\Mall\Entities\Mall;
use Modules\Mall\Http\Requests\CateRequest;
class CateController extends Controller
{
    //显示列表
    public function index()
    {
        $data = Cate::paginate(10);
        return view('mall::cate.index', compact('data'));
    }

    //创建视图
    public function create(Cate $cate)
    {
        return view('mall::cate.create',compact('cate'));
    }

    //保存数据
    public function store(CateRequest $request,Cate $cate)
    {
        $cate->fill($request->all());
        $cate->save();

        return redirect('/mall/cate')->with('success', '保存成功');
    }

    //显示记录
    public function show(Cate $field)
    {
        return view('mall::cate.show', compact('field'));
    }

    //编辑视图
    public function edit(Cate $cate)
    {
        return view('mall::cate.edit', compact('cate'));
    }

    //更新数据
    public function update(CateRequest $request, Cate $cate)
    {
        $cate->update($request->all());
        return redirect('/mall/cate')->with('success','更新成功');
    }

    //删除模型
    public function destroy(Cate $cate)
    {
        $m=Mall::where('cid',$cate['id'])->first();
        if($m){
        	session()->flash('danger','该分类下有店铺，不能删除！');
        	return redirect ()->back();
		}
		$cate->delete();
        return redirect('mall/cate')->with('success','删除成功');
    }
}
